"================================================
" 
" 	Edit by 4eburashk http://csn.net4me.net
" 		On Fri 04 Aug 2023 05:49:21 PM MSK
" 		
"================================================
	if v:lang =~ "utf8$" || v:lang =~ "UTF-8$"
		set fileencodings=utf-8,latin1
	endif
	if v:progname =~? "evim"
		finish
	endif
" This must be first, because it changes other options as a side effect.
	set nocompatible
	set backspace=indent,eol,start
	set history=90          " keep 80 lines of command line history
	set ruler               " show the cursor position all the time
	set showcmd             " show partial command in status line
	set viminfo='90,%,n~/.viminfo
	set mouse-=a						" visual mouse off
	set ttymouse=						" visual ttymouse off
" Don't use Ex mode, use Q for formatting
	map Q gq
" GUI colors:
	if &t_Co > 2 || has("gui_running")
		syntax on
		set hlsearch
  	" my for not beep:
  	set vb t_vb="<Esc>|40f"
  	" my for olors:
  	":colorscheme net4me
	endif
" Force write file w! with sudo:
	cnoremap w! execute 'silent! write !sudo tee % >/dev/null' <bar> edit!
" Only do this part when compiled with support for autocommands.
	if has("autocmd")
		" always jump to the last cursor position
		autocmd BufReadPost *
		\ if line("'\"") > 0 && line ("'\"") <= line("$") |
		\   exe "normal! g'\"" |
		\ endif
		"Templetes. for autocreate files content. Change paths to your template files:
		if isdirectory($HOME."/vim/mytemplates")
			:autocmd BufNewFile  *.sh    0r $HOME/vim/mytemplates/bash.txt
			:autocmd BufNewFile  *.py    0r $HOME/vim/mytemplates/python.txt
			:autocmd BufNewFile  *.html  0r $HOME/vim/mytemplates/html.txt
			:autocmd BufNewFile  *.c     0r $HOME/vim/mytemplates/c.txt
			:autocmd BufNewFile  *.cpp   0r $HOME/vim/mytemplates/cpp.txt
			:autocmd BufNewFile  *.h     0r $HOME/vim/mytemplates/h.txt
			:autocmd BufNewFile  *.pl    0r $HOME/vim/mytemplates/perl.txt
			:autocmd BufNewFile  *.rb    0r $HOME/vim/mytemplates/ruby.txt
			:autocmd BufNewFile  *.go    0r $HOME/vim/mytemplates/go.txt
		endif
		" php-fpm config syntax:
		:autocmd BufRead,BufNewFile /etc/php*.conf set syntax=dosini
		"change dir to current:
		:autocmd BufEnter * lcd %:p:h
	endif

	if has("title")
		set notitle
		set noicon
	endif

" undo:
	if !isdirectory($HOME."/.vim")
		call mkdir($HOME."/.vim", "", 0770)
	endif
	if !isdirectory($HOME."/.vim/undo")
		call mkdir($HOME."/.vim/undo", "", 0700)
	endif
	set undodir=~/.vim/undo/
	set undofile
	set undolevels=1000   " How many undos
	set undoreload=10000  " number of lines to save for undo

" Tab = (2*spaces)
	set tabstop=2
	set sw=2
	set nomodeline
	set noautoindent
" In search:
	set ignorecase
" new file in Right window:
	set splitright
" Stamp (i mode):
	imap <F4> <C-R>=MyStamp()<CR>
	function! MyStamp()
		let myhead = "\n\tEdit by 4eburashk http://csn.net4me.net\n\tOn "
		\ . strftime("%c")
		\ . "\n\n"
		return myhead
	endfunction

" HEX view on/off:
	map <F3> :Hex4me<CR>
" hex command for toggling hex mode - define mapping if desired
	command -bar Hex4me call HexView()
	" hex mode helper
	function HexView()
		" hex mode should be considered a read-only operation
		" save values for modified and read-only for restoration later,
		" and clear the read-only flag for now
		let l:modified=&mod
		let l:oldreadonly=&readonly
		let &readonly=0
		let l:oldmodifiable=&modifiable
		let &modifiable=1
		if !exists("b:editHex") || !b:editHex
			" save old options
			let b:oldft=&ft
			let b:oldbin=&bin
			" set new options
			setlocal binary " make sure it overrides any textwidth, etc.
			let &ft="xxd"
			" set status
			let b:editHex=1
			" switch to hex editor
			%!xxd
		else
			" restore old options
			let &ft=b:oldft
			if !b:oldbin
				setlocal nobinary
			endif
			" set status
			let b:editHex=0
			" return to normal editing
			%!xxd -r
		endif
		" restore values for modified and read only state
		let &mod=l:modified
		let &readonly=l:oldreadonly
		let &modifiable=l:oldmodifiable
	endfunction

" Comments:
	augroup commenting_blocks_of_code
	  autocmd!
	  autocmd FileType c,cpp,java,php,go,ino let b:comment_leader = '// '
	  autocmd FileType sh,perl,ruby,python,awk   let b:comment_leader = '# '
	  autocmd FileType conf,fstab,nginx,yaml let b:comment_leader = '# '
	  autocmd FileType mail             let b:comment_leader = '> '
	  autocmd FileType vim              let b:comment_leader = '" '
	augroup END
	noremap <silent> <F5> :<C-B>silent <C-E>s/^/<C-R>=escape(b:comment_leader,'\/')<CR>/<CR>:nohlsearch<CR>
	noremap <silent> <F6> :<C-B>silent <C-E>s/^\V<C-R>=escape(b:comment_leader,'\/')<CR>//e<CR>:nohlsearch<CR>

" autocompletion {<Enter>}
" imap {<CR> {<CR>}<Esc>O<Tab>

" Encoding old win:
" <F7> EOL format (dos <CR><NL>,unix <NL>,mac <CR>)
	set  wildmenu
	set  wcm=<Tab>
	menu EOL.unix :set fileformat=unix<CR>
	menu EOL.dos  :set fileformat=dos<CR>
	menu EOL.mac  :set fileformat=mac<CR>
	menu EOL.my_win2unix :%s /\r\n/\r/g<CR>
	map  <F7> :emenu EOL.<Tab>
" <F8> Change encoding
	set  wildmenu
	set  wcm=<Tab>
	menu Enc.cp1251     :e ++enc=cp1251<CR>
	menu Enc.koi8-r     :e ++enc=koi8-r<CR>
	menu Enc.cp866      :e ++enc=ibm866<CR>
	menu Enc.utf-8      :e ++enc=utf-8<CR>
	menu Enc.ucs-2le    :e ++enc=ucs-2le<CR>
	menu Enc.HexView    :Hex4me<CR>
	map  <F8> :emenu Enc.<Tab>
" <Shift+F8> Convert file encoding
	set  wildmenu
	set  wcm=<Tab>
	menu FEnc.cp1251    :set fenc=cp1251<CR>
	menu FEnc.koi8-r    :set fenc=koi8-r<CR>
	menu FEnc.cp866     :set fenc=ibm866<CR>
	menu FEnc.utf-8     :set fenc=utf-8<CR>
	menu FEnc.ucs-2le   :set fenc=ucs-2le<CR>
	map  <S-F8> :emenu FEnc.<Tab>
" <TAB> left/right indent. v mode :
	:vmap <Tab> >gv
	:vmap <S-Tab> <gv

" Status line:
	set statusline="%<%f%h%m%r%=format=%{&fileformat}\ file=%{&fileencoding}\ enc=%{&encoding}\ %b\ 0x%B\ %l,%c%V\ %P"
	set laststatus=2

" YCM youcompleteme:
	try 
		"highlight YcmWarningSection ctermbg=1 guibg=#800000
		highlight Pmenu ctermfg=7 ctermbg=1 guifg=#ffffff guibg=#800000
		set signcolumn=no " убрать выпрыгивающую хрень слева со стрелочками. >>
	catch
	endtry
" vim :set et ts=2 sw=2 sts=2
" END
